package com.dhnsoft.education.schedule;

import com.dhnsoft.education.service.statistics.StatisticsDailyService;
import com.dhnsoft.education.utils.statistics.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @Description
 * @ClassName ScheduleTask
 * @Author dhn
 * @date 2022.04.18 18:21
 */
@Component
public class ScheduleTask {

    @Autowired
    private StatisticsDailyService statisticsDailyService;

//    //0/5 * * * * ? 表示每隔5秒执行一次这个方法
//    @Scheduled(cron = "0/5 * * * * ?")
//    public void task1(){
//        System.out.println("******task1执行了..");
//    }

    //在每天凌晨一点去执行查询前一天的数据，把数据查询进行添加
    @Scheduled(cron = "0 0 1 * * ? ")
    public void task2(){
        //当前日期的前一天
        statisticsDailyService.registerCount(DateUtil.formatDate(DateUtil.addDays(new Date(),-1)));
    }
}
